<tagLib name="html" />
<script type="text/javascript">
	function add_order() {
		$("#form_order :input :not(:button) :not('select')").each(function() {
			$(this).val("");
		});
		$("#form_order :text").each(function() {
			$(this).val("");
		});
		$("#form_order select").each(function() {
			$(this).find('option:first').attr('selected', 'selected');
		});
		$(".order_sub_left_menu tr.active").removeClass("active");
		$("#order_opmode").val("add");
	}

	function save_order() {
		if(check_form("form_order")){
      sendForm("form_order", "{:U('order/save')}",window.location.href);
		}		
	}

  function destroy_order() {
    var id = $(".order_sub_left_menu  tr.active").attr('id');
    if(id==undefined){
      alert('请先选择联系记录');
      return false;
    }
    sendAjax("{:U('order/del')}", "id=" + id, function(data) {
        if(data['status']=='1'){
          alert(data['info']);
        }else{
          alert('未成功！'); 
        };
       location.reload();
    });
  }

	function showdata(result) {
		for (var s in result.data) {
			set_val(s,result.data[s]);
		}
    $('#order_id').val(result.data['id']);
    //$("#contact_result_id_"+result.data['contact_result_id']).click(); 
		$("#save_name").val("");
		$("#opmode").val("edit");
	}

	$(document).ready(function(){		
  	$(".input-date").datepicker();
		$(".order_sub_left_menu  tr").click(function() {
			$(".order_sub_left_menu  tr.active").removeClass("active");
      $('#order_opmode').val('edit');
      //alert($(this).attr('id'));
      $('#real_order_id').val($(this).attr('id'));
			$(this).attr("class","active");
			sendAjax("{:U('order/read')}", "id=" + $(this).attr("id"), function(data) {
				showdata(data);
			});
			return false;
		})
	});

</script>
<div class="admin" >
	<form method="post" action="" id="form_search" name="form_search">
		<div class="row-fluid title">
      <a href="javascript:void($('#order').toggle())">
        <span>订单管理</span>
      </a>
		</div>
	</form>
  <div id="order" style="display:none;">
	<div class="row-fluid operate" >
		<div class="right">
			<a onclick="add_order()"  class="btn">新增</a>
			<a onclick="save_order()"  class="btn">保存</a>
			<a onclick="destroy_order()"  class="btn">删除</a>
		</div>
	</div>
  <?php 
 // echo print_r($order_list);
  ?>
	<div class="row-fluid">
		<div class="span4 order_sub_left_menu ">
			<table class="table table-bordered">
				<tr>
					<th>订单编号</th>
					<th>创建日期</th>
					<th>订单金额</th>
					<th>审核状态</th>
				</tr>
				<volist name="order_list" id="order">
					<tr id="{$order.id}">
						<td>{$order.number}</td>
            <td><?php echo $order['created_at'] ?></td>
            <td><?php echo $order['contract_amount'] ?></td>
            <td><?php echo $order['check_status'] == 1 ? '审核中' : '已审核' ?></td>
					</tr>
				</volist>
			</table>
		</div>
		<div class="span8">
			<form id="form_order" name="form_order" method="post" action="">
				<input type="hidden" id="save_name" name="save_name">
				<input type="hidden" name="id" id="real_order_id">
				<input type="hidden" name="pid" id="order_pid" value="">
        <input type="hidden" name="mini_client_id" id="order_mini_client_id" value="{$vo.id}">
				<input type="hidden" name="pic" id="order_pic" >
				<input type="hidden" name="ajax" id="order_ajax" value="1">
				<input type="hidden" name="opmode" id="order_opmode" value="">
        <input type="hidden" name="number" id="order_number" value="<?php echo "000$order_count" ?>">
        <input type="hidden" name="created_at" id="order_created_at" value="<?php echo date('Y-m-d H:i:s'); ?>">
				<table class="table table-bordered" >
					<tr>
						<th>联系人*</th>
            <?php 
            foreach ($lianxiren_list as $lxr ) {
              $lianxiren_select_list[$lxr['id']] = $lxr['name'];
            }
            ?>
						<td>
              <html:select id="contact_person_id" name="contact_person_id"  options="lianxiren_select_list" style="input-small"/>
            </td>
          </tr>
          <tr class="order_item">
						<th>产品</th>
						<td>
              <html:select id="product_id" name="product_id"  options="product_list" style="input-small"/>
						</td>
					</tr>
					<tr class='order_item' style=";">
						<th>合同总价</th>
						<td colspan=3>
              <input type="text" id="contract_amount" name="contract_amount" class="span12">
						</td>
					</tr>
					<tr class='order_item' style=";">
						<th>已收款项</th>
						<td colspan=3>
              <input type="text" id="received_amount" name="received_amount" class="span12">
						</td>
					</tr>
					<tr class="order_item" style=";">
						<th>服务开始时间</th>
						<td colspan=3>
              <input type="text" id="serve_start_at" name="serve_start_at" class="span12 input-date">
						</td>
					</tr>
					<tr class='order_item' style=";">
						<th>服务结束时间</th>
						<td colspan=3>
              <input type="text" id="serve_end_at" name="serve_end_at" class="span12 input-date">
						</td>
					</tr>
					<tr class='order_item' style=";">
						<th>续费标准</th>
						<td colspan=3>
              <input type="text" id="fee_standard" name="fee_standard" class="span12">
						</td>
					</tr>
					<tr class="order" style="">
						<th>订单备注</th>
						<td colspan="3">
              <textarea type="text" name="description" id="description" class="span12" rows='3'></textarea>
						</td>
						</td>
					</tr>
				</table>
			</form>
		</div>
    <div id="order_page">
    </div>
	</div>
</div>
</div>
